Estoy haciendo un programa en Phaser en JavaScript y estoy usando la instrucción questions.setVisible(false) en mi programa, pero aparece: Uncaught TypeError: question.setVisible is not a function , que claramente lo es. La declaración está en la función de create , tampoco funciona en las otras funciones. Código:
var Game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', {create}) var question; function create() { question = Game.add.text(Game.width/2, Game.height/2, 'On which day is Pi celebrated?', {align: 'center'}).anchor.setTo(0.5); question.setVisible(false); }Recomendaría usar Phaser 3 , no Phaser 2/CE/... más o menos. Dado que la mayoría de las documentaciones e información son para Phaser 3. Dicho esto, me parece que su problema es doble:
no puede encadenar todas las propiedades/métodos de esta manera, ya que los comentarios mencionan que devuelve un objeto diferente. Tendrías que hacer esto:
// like this `question` is a Text object question = game.add.text(game.width/2,game.height/2, 'On which day is Pi celebrated?', {align: 'center', stroke:'white', fill:'white'}); // set the anchor of the `question` question.anchor.setTo(0.5); la función setVisible no existe para la clase de texto. (al menos no se menciona en la documentación , nota al margen: en phaser3 existe esta función). Para Phaser 2/CE tendría que establecer la propiedad visible :
question.visible = false;Así que toda la función debería verse así:
function create() { question = game.add.text(game.width/2,game.height/2, '...', {align: 'center'}); question.anchor.setTo(0.5); question.visible = false; }